<!-- ------------------------------------------------------------------------- -->
<!-- ------------------------------------------------------------------------- -->
<!-- ---------------------- 流调管理--确诊病例管理 ---------------------------- -->
<!-- ------------------------------------------------------------------------- -->
<!-- ------------------------------编辑的tag---------------------------------- -->
<!-- -------------------------编辑的tag--流行病学调查----------------------------- -->

<template>
  <div class="box">
    <el-form
      ref="ruleFormRef"
      :model="ruleForm"
      :rules="rules"
      label-width="120px"
      class="demo-ruleForm"
      :size="formSize"
      status-icon
    >
      <el-form-item label="回溯时间:" prop="count">
        <el-date-picker
          v-model="value1"
          type="date"
          placeholder="Pick a date"
          :default-value="new Date(2010, 9, 1)"
          style="width: 375px"
        />
      </el-form-item>

      <el-row>
        <el-col :span="24"
          ><div class="grid-content ep-bg-purple-dark" />
          <el-form-item
            label="旅居生活史、阳性个案接触史:"
            prop="count"
            style="margin-right: 100px; width: 500px"
          >
            <el-input v-model="ruleForm.count" style="height: 150px" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="24"
          ><div class="grid-content ep-bg-purple-dark" />
          <el-form-item
            label="症状:"
            prop="count"
            style="margin-right: 100px; width: 500px"
          >
            <el-input v-model="ruleForm.count" style="height: 150px" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-form-item label="检测阳性日期:" prop="count">
        <el-date-picker
          v-model="value1"
          type="date"
          placeholder="Pick a date"
          :default-value="new Date(2010, 9, 1)"
          style="width: 375px"
        />
      </el-form-item>

      <el-form-item label="轨迹调查:" prop="count"> </el-form-item>

      <el-button type="primary" @click="addForm = true">新增</el-button>
      <!-- 新增模态框 -->
      <el-dialog v-model="addForm" title="新增流行病学轨迹">
        <el-form :model="form" style="padding-top: 30px">
          <el-form-item label="时间:" :label-width="formLabelWidth">
            <div class="demo-date-picker">
              <div class="block">
                <el-date-picker
                  v-model="addDate"
                  type="date"
                  placeholder="请选择"
                  :disabled-date="disabledDate"
                  :size="size"
                  style="width: 300px"
                />
              </div>
            </div>
          </el-form-item>

          <el-form-item
            label="地点:"
            :label-width="formLabelWidth"
            size="large"
          >
            <el-input
              v-model="form.name"
              autocomplete="off"
              style="width: 90%"
            />
          </el-form-item>
          <!-- img -->
          <el-form-item
            label="接触人:"
            :label-width="formLabelWidth"
            size="large"
          >
            <el-input
              v-model="form.name"
              autocomplete="off"
              style="width: 90%"
              placeholder="请输入"
            />
          </el-form-item>
          <el-form-item
            label="活动:"
            :label-width="formLabelWidth"
            size="large"
          >
            <el-input
              v-model="form.name"
              autocomplete="off"
              style="width: 90%"
              placeholder="请输入"
            />
          </el-form-item>
          <el-form-item
            label="交通工具:"
            :label-width="formLabelWidth"
            size="large"
          >
            <el-input
              v-model="form.name"
              autocomplete="off"
              style="width: 90%"
              placeholder="请输入"
            />
          </el-form-item>
          <el-form-item
            label="个人防护情况:"
            :label-width="formLabelWidth"
            size="large"
          >
            <el-input
              v-model="form.name"
              autocomplete="off"
              style="width: 90%"
              placeholder="请输入"
            />
          </el-form-item>
          <el-form-item
            label="对方防护情况:"
            :label-width="formLabelWidth"
            size="large"
          >
            <el-input
              v-model="form.name"
              autocomplete="off"
              style="width: 90%"
              placeholder="请输入"
            />
          </el-form-item>
        </el-form>
        <template #footer>
          <span class="dialog-footer">
            <el-button @click="addForm = false">取消</el-button>
            <el-button type="primary" @click="addForm = false">
              确定
            </el-button>
          </span>
        </template>
      </el-dialog>

      <el-timeline class="table">
        <el-timeline-item timestamp="2018/4/12" placement="top">
          <div class="btn-box">
            <el-button type="primary" :icon="Edit" circle size="small" @click="editForm = true"  />
            <!-- 编辑模态框 -->
            <el-dialog v-model="editForm" title="编辑流行病学轨迹">
              <el-form :model="eForm" style="padding-top: 30px; width: 100%">
                <el-form-item label="时间:" :label-width="formLabelWidth">
                  <div class="demo-date-picker">
                    <div class="block">
                      <el-date-picker
                        v-model="editForm"
                        type="date"
                        placeholder="请选择"
                        :disabled-date="disabledDate"
                        :size="size"
                        style="width: 300px"
                      />
                    </div>
                  </div>
                </el-form-item>

                <el-form-item
                  label="地点:"
                  :label-width="formLabelWidth"
                  size="large"
                >
                  <el-input
                    v-model="eForm.name"
                    autocomplete="off"
                    style="width: 90%"
                  />
                </el-form-item>
                <!-- img -->
                <el-form-item
                  label="接触人:"
                  :label-width="formLabelWidth"
                  size="large"
                >
                  <el-input
                    v-model="eForm.name"
                    autocomplete="off"
                    style="width: 90%"
                    placeholder="请输入"
                  />
                </el-form-item>
                <el-form-item
                  label="活动:"
                  :label-width="formLabelWidth"
                  size="large"
                >
                  <el-input
                    v-model="eForm.name"
                    autocomplete="off"
                    style="width: 90%"
                    placeholder="请输入"
                  />
                </el-form-item>
                <el-form-item
                  label="交通工具:"
                  :label-width="formLabelWidth"
                  size="large"
                >
                  <el-input
                    v-model="eForm.name"
                    autocomplete="off"
                    style="width: 90%"
                    placeholder="请输入"
                  />
                </el-form-item>
                <el-form-item
                  label="个人防护情况:"
                  :label-width="formLabelWidth"
                  size="large"
                >
                  <el-input
                    v-model="eForm.name"
                    autocomplete="off"
                    style="width: 90%"
                    placeholder="请输入"
                  />
                </el-form-item>
                <el-form-item
                  label="对方防护情况:"
                  :label-width="formLabelWidth"
                  size="large"
                >
                  <el-input
                    v-model="eForm.name"
                    autocomplete="off"
                    style="width: 90%"
                    placeholder="请输入"
                  />
                </el-form-item>
              </el-form>
              <template #footer>
                <span class="dialog-footer">
                  <el-button @click="editForm = false">取消</el-button>
                  <el-button type="primary" @click="editForm = false">
                    确定
                  </el-button>
                </span>
              </template>
            </el-dialog>
            <el-button style="margin-left:12px;" type="danger" :icon="Delete" circle size="small" @click="deleteForm" />

          </div>
          <el-row>
            <el-col :span="6" class="title"
              ><div class="grid-content ep-bg-purple" />
              <p>地点:</p>
            </el-col>
            <el-col :span="18" class="banner"
              ><div class="grid-content ep-bg-purple-light" />
              <p>苏州市山塘街星巴克咖啡馆</p>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="6" class="title"
              ><div class="grid-content ep-bg-purple" />
              <p>地点:</p>
            </el-col>
            <el-col :span="18" class="banner"
              ><div class="grid-content ep-bg-purple-light" />
              <p>苏州市山塘街星巴克咖啡馆</p>
            </el-col> </el-row
          ><el-row>
            <el-col :span="6" class="title"
              ><div class="grid-content ep-bg-purple" />
              <p>地点:</p>
            </el-col>
            <el-col :span="18" class="banner"
              ><div class="grid-content ep-bg-purple-light" />
              <p>苏州市山塘街星巴克咖啡馆</p>
            </el-col> </el-row
          ><el-row>
            <el-col :span="6" class="title"
              ><div class="grid-content ep-bg-purple" />
              <p>地点:</p>
            </el-col>
            <el-col :span="18" class="banner"
              ><div class="grid-content ep-bg-purple-light" />
              <p>苏州市山塘街星巴克咖啡馆</p>
            </el-col> </el-row
          ><el-row>
            <el-col :span="6" class="title"
              ><div class="grid-content ep-bg-purple" />
              <p>地点:</p>
            </el-col>
            <el-col :span="18" class="banner"
              ><div class="grid-content ep-bg-purple-light" />
              <p>苏州市山塘街星巴克咖啡馆</p>
            </el-col> </el-row
          ><el-row>
            <el-col :span="6" class="title"
              ><div class="grid-content ep-bg-purple" />
              <p>地点:</p>
            </el-col>
            <el-col :span="18" class="banner"
              ><div class="grid-content ep-bg-purple-light" />
              <p>苏州市山塘街星巴克咖啡馆</p>
            </el-col>
          </el-row>
        </el-timeline-item>

        <el-timeline-item timestamp="2018/4/12" placement="top">
          <div class="btn-box">
            <el-button
              type="primary"
              :icon="Edit"
              circle
              size="small"
              @click="editForm = true"
            />
            

            <el-button type="danger" :icon="Delete" circle size="small" @click="deleteForm" />
          </div>
          <el-row>
            <el-col :span="6" class="title"
              ><div class="grid-content ep-bg-purple" />
              <p>地点:</p>
            </el-col>
            <el-col :span="18" class="banner"
              ><div class="grid-content ep-bg-purple-light" />
              <p>苏州市山塘街星巴克咖啡馆</p>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="6" class="title"
              ><div class="grid-content ep-bg-purple" />
              <p>地点:</p>
            </el-col>
            <el-col :span="18" class="banner"
              ><div class="grid-content ep-bg-purple-light" />
              <p>苏州市山塘街星巴克咖啡馆</p>
            </el-col> </el-row
          ><el-row>
            <el-col :span="6" class="title"
              ><div class="grid-content ep-bg-purple" />
              <p>地点:</p>
            </el-col>
            <el-col :span="18" class="banner"
              ><div class="grid-content ep-bg-purple-light" />
              <p>苏州市山塘街星巴克咖啡馆</p>
            </el-col> </el-row
          ><el-row>
            <el-col :span="6" class="title"
              ><div class="grid-content ep-bg-purple" />
              <p>地点:</p>
            </el-col>
            <el-col :span="18" class="banner"
              ><div class="grid-content ep-bg-purple-light" />
              <p>苏州市山塘街星巴克咖啡馆</p>
            </el-col> </el-row
          ><el-row>
            <el-col :span="6" class="title"
              ><div class="grid-content ep-bg-purple" />
              <p>地点:</p>
            </el-col>
            <el-col :span="18" class="banner"
              ><div class="grid-content ep-bg-purple-light" />
              <p>苏州市山塘街星巴克咖啡馆</p>
            </el-col> </el-row
          ><el-row>
            <el-col :span="6" class="title"
              ><div class="grid-content ep-bg-purple" />
              <p>地点:</p>
            </el-col>
            <el-col :span="18" class="banner"
              ><div class="grid-content ep-bg-purple-light" />
              <p>苏州市山塘街星巴克咖啡馆</p>
            </el-col>
          </el-row>
        </el-timeline-item>
      </el-timeline>

      <el-form-item style="padding-top: 200px">
        <el-button @click="resetForm(ruleFormRef)">取消</el-button>
        <el-button type="primary" @click="submitForm(ruleFormRef)">
          确定
        </el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script lang="ts">
import { defineComponent, reactive, ref } from "vue";
import type { FormInstance, FormRules } from "element-plus";
import { ElMessage, ElMessageBox } from 'element-plus'
import { Delete, Edit } from "@element-plus/icons-vue";
export default defineComponent({
  name: "RiskFactors",
  setup() {
    const formSize = ref("large");
    const ruleFormRef = ref<FormInstance>();
    const value1 = ref("");
    const addDate = ref(""); //登记日期选择
    const size = ref<"default" | "large" | "small">("large"); //新增---时间
    // 新增
    const dialogTableVisible = ref(false);
    const addForm = ref(false);
    const formLabelWidth = "140px";
    //编辑
    const editForm = ref(false);
    const ruleForm = reactive({
      name: "Hello",
      region: "",
      count: "",
      date1: "",
      date2: "",
      delivery: false,
      type: [],
      resource: "",
      desc: "",
    });

    // 新增
    const addEpidemic = () => {};
    const form = reactive({
      name: "",
      region: "",
      date1: "",
      date2: "",
      delivery: false,
      type: [],
      resource: "",
      desc: "",
    });

    const eForm = reactive({
      name: "",
      region: "",
      date1: "",
      date2: "",
      delivery: false,
      type: [],
      resource: "",
      desc: "",
    });

    // 删除
    const deleteForm = () => {
  ElMessageBox.confirm(
    '删除后将不可恢复,是否继续此操作?',
    '删除确认',
    {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning',
    }
  )
    .then(() => {
      ElMessage({
        type: 'success',
        message: '删除成功',
      })
    })
    .catch(() => {
      ElMessage({
        type: 'info',
        message: '删除失败',
      })
    })
}

    const gridData = [
      {
        date: "2016-05-02",
        name: "John Smith",
        address: "No.1518,  Jinshajiang Road, Putuo District",
      },
      {
        date: "2016-05-04",
        name: "John Smith",
        address: "No.1518,  Jinshajiang Road, Putuo District",
      },
      {
        date: "2016-05-01",
        name: "John Smith",
        address: "No.1518,  Jinshajiang Road, Putuo District",
      },
      {
        date: "2016-05-03",
        name: "John Smith",
        address: "No.1518,  Jinshajiang Road, Putuo District",
      },
    ];

    //登记日期禁用函数
    const disabledDate = (time: Date) => {
      return time.getTime() > Date.now();
    };

    const rules = reactive<FormRules>({
      name: [
        {
          required: true,
          message: "Please input Activity name",
          trigger: "blur",
        },
        { min: 3, max: 5, message: "Length should be 3 to 5", trigger: "blur" },
      ],
      region: [
        {
          required: true,
          message: "Please select Activity zone",
          trigger: "change",
        },
      ],
      count: [
        {
          required: false,
          message: "Please select Activity count",
          trigger: "change",
        },
      ],
      date1: [
        {
          type: "date",
          required: true,
          message: "Please pick a date",
          trigger: "change",
        },
      ],
      date2: [
        {
          type: "date",
          required: true,
          message: "Please pick a time",
          trigger: "change",
        },
      ],
      type: [
        {
          type: "array",
          required: true,
          message: "Please select at least one activity type",
          trigger: "change",
        },
      ],
      resource: [
        {
          required: true,
          message: "Please select activity resource",
          trigger: "change",
        },
      ],
      desc: [
        {
          required: true,
          message: "Please input activity form",
          trigger: "blur",
        },
      ],
    });

    const submitForm = async (formEl: FormInstance | undefined) => {
      if (!formEl) return;
      await formEl.validate((valid, fields) => {
        if (valid) {
          console.log("submit!");
        } else {
          console.log("error submit!", fields);
        }
      });
    };

    const resetForm = (formEl: FormInstance | undefined) => {
      if (!formEl) return;
      formEl.resetFields();
    };

    const options = Array.from({ length: 10000 }).map((_, idx) => ({
      value: `${idx + 1}`,
      label: `${idx + 1}`,
    }));

    return {
      formSize,
      ruleFormRef,
      ruleForm,
      rules,
      submitForm,
      resetForm,
      options,
      value1,
      Delete,
      Edit,
      addEpidemic,
      dialogTableVisible,
      addForm,
      formLabelWidth,
      form,
      gridData,
      size,
      addDate,
      disabledDate,
      editForm,
      eForm,
      deleteForm
    };
  },
});
</script>

<style scoped lang="less">
.box {
  width: 100%;
  background-color: #fff;
}
.el-form {
  width: 90%;
  background-color: #fff;
  padding-top: 100px;
}
.el-timeline {
  margin-top: 30px;
}
.table {
  .el-col {
    border: 0.5px solid rgba(0, 0, 0, 0.04);
    height: 50px;
    display: flex;
    align-items: center;
  }
}

.title {
  background-color: #f9f9f9;
  display: flex;
  justify-content: flex-end;
  padding-right: 10px;
}
.banner {
  display: flex;
  padding-left: 10px;
}
.btn-box {
  height: 30px;
}
</style>
